package com.hmall.api.interceptor;

import com.hmall.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;

/**
 * 远程调用前的做一些预处理，给请求添加请求头user-info
 * RequestInterceptor: Feign提供的拦截器。
 * @author 16701
 */
@Component
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        Long userId = UserContext.getUser();
        if(userId!=null){
            requestTemplate.header("user-info",userId.toString());
        }
    }
}
